<?php
//week string
$week_array = BUtils::WeekDayKeys(7, true);

//set offer picture
$url_thumb_default = Yii::app()->baseUrl . '/images/default_special_thumb.png';
$url_picture_default = Yii::app()->baseUrl . '/images/default_special_picture.png';
$url_thumb = empty($r['url_picture']) ? $r['url_offer_img'] : $r['url_picture'];
if (!empty($url_thumb)) {
	$url_thumb = BUtils::GetOfferThumbUrl($url_thumb);
	$url_picture = str_replace('thumb_', '', $url_thumb);
} else {
	$url_thumb = $url_thumb_default;
	$url_picture = $url_picture_default;
}

//set price, discount or highlight
$highlight = $del_price = '';
if (!empty($r['price'])) {
	$highlight = MerchantObject::formatPrice($r['price']);
	if (!empty($r['value'])) {
		$del_price = '<span class="oldprice label">€'.$r['value'].'</span>';
	}
} elseif (!empty($r['discount'])) {
	$highlight = MerchantObject::formatDiscount($r['discount']);
}

//set day string
$week_string = BUtils::GetWeekdays($r['week_days'], $week_array);
$range_date = BUtils::GetRecentDayName($r['week_days'], $week_string, false, $r['start_hour']);
$range_time = BUtils::GetHourRangeFormat($r['start_hour'], $r['end_hour']);

//set date range
$valid_peroid = BUtils::GetDateRangeString($r['uts_start_date'], $r['uts_end_date']);

//business icon url
$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_others.png';
if (!empty($r['category_key'])) {
	$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_'.$r['category_key'].'.png';
}

//offer content
$content = nl2br(strip_tags(trim($r['content'])));

$max_number_msg = '';
if ($r['max_number'] > 0) {
	$max_number_msg = '<div class="remaining">' . BUtils::T('offer_remaining_lbl', array('{number}' => $r['max_number'])) . '</div>';
}

//address
$biz_address = '';
if (!empty($r['address'])) {
	$biz_address = $r['address'];
	if (!empty($r['biz_area'])) $biz_address .= ', ' . $r['biz_area'];
	if (!empty($r['postcode'])) $biz_address .= '<br />' . $r['postcode'] . ' ' . $r['city'];
}

//how to use tips
if ($r['redeem_type'] == 1) {
	$how_to_redeem_icon = '<img src="'.Yii::app()->baseUrl.'/images/icons/using_show.png" alt="" />';
	$how_to_redeem_msg = BUtils::T('special_using_show_lbl');
} else {
	$how_to_redeem_icon = '<img src="'.Yii::app()->baseUrl.'/images/icons/using_scan.png" alt="" />';
	$how_to_redeem_msg = BUtils::T('special_using_scan_lbl');
}
?>
<div class="offer_v" style="width:360px;">
	<div class="image">
		<img src="<?php echo $url_picture; ?>" alt="" onError="this.onerror=null;this.src='<?php echo Yii::app()->baseUrl; ?>/images/default_special_picture.png';" />
		<div class="info">
			<div class="mb_price">
				<div class="highlight"><?php echo $highlight; ?></div>
				<?php echo $del_price; ?>
			</div>
			<div class="mb_period">
				<div class="time"><?php echo $range_time; ?></div>
				<div class="date"><?php echo $range_date; ?></div>
			</div>
			<div class="clearfix"></div>
		</div>
	</div>
	<div class="action">
		<div class="margin">
			<div class="icon"><?php echo $how_to_redeem_icon; ?></div>
			<div class="tips"><?php echo $how_to_redeem_msg; ?></div>
			<div class="clearfix"></div>
		</div>
	</div>
	<div class="detail">
		<?php echo $max_number_msg; ?>
		<div class="margin">
			<div class="title"><?php echo BUtils::T('special_valid_date_lbl'); ?></div>
			<div class="clearfix text">
				<?php echo $valid_peroid; ?>
				<br />
				<?php echo $week_string; ?>
			</div>
		</div>
		<div class="margin">
			<div class="title"><?php echo BUtils::T('special_content_lbl'); ?></div>
			<div class="text">
				<?php echo $content; ?>
			</div>
		</div>
		<div class="margin">
			<div class="title"><?php echo BUtils::T('address_lbl'); ?></div>
			<div class="clearfix text">
				<?php echo $biz_address; ?>
			</div>
		</div>
		<div class="margin">
			<div class="clearfix text">
<?php
foreach ($r['thumbs'] as $url) {
	$url = BUtils::GetOfferPictureUrl($url);
	echo '<img src="'.$url.'" style="width:100%;" />';
}
?>
			</div>
		</div>
	</div>
</div>